package com.itxx.homework;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Test2 {
    public static void main(String[] args) {
        //88.5,39.2,77.1,56.8,89,99,59.5
//        Collection<String> c = new ArrayList<>();
        Collection<Double> c = new ArrayList<>();
        c.add(88.5);
        c.add(39.2);
        c.add(77.1);
        c.add(56.8);
        c.add(89.0);
        c.add(99.0);
        c.add(59.5);


        //1.	使用增强for遍历所有元素，并打印
        Iterator<Double> iterator = c.iterator();
        for (Double s : c) {
            System.out.println(s);
        }
        System.out.println("----------");
        //2.使用增强for遍历所有元素，打印不及格的分数；
        for (Double s : c) {
            if (s < 60) {
                System.out.println("不及格的分数:" + s);
            }
        }
        System.out.println("----------");

        //3.	使用增强for遍历所有元素，计算不及格的分数的数量，和平均分，并打印计算结果。
        int count = 0;
        Double sum = 0.0;
        for (Double s : c) {
            if (s < 60) {
                count++;
            }
            sum += s;
        }
        Double avg = sum / c.size();
        System.out.println("总分是:" + sum);
        System.out.println("平均分为:" + avg);
        System.out.println("不及格的分数有:" + count + "个");
        System.out.println("----------");

        //4.	使用增强for遍历所有元素，求出最高分，并打印
       /* double max = 0.0;
        Iterator<Double> iterator1 = c.iterator();
        for (Double aDouble : c) {
             max = Math.max(aDouble, max);
        }
        System.out.println("最高值"+max);
*/
        double max = -1;
        for (Double aDouble : c) {
            max = (max > aDouble) ? max : aDouble;
        }
        System.out.println("最高值" + max);
    }
}

